package com.yaozheng.vocationaltraining.fragment;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.FragmentArg;
import org.androidannotations.annotations.ViewById;

import android.content.Intent;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.activity.HomeActivity;
import com.yaozheng.vocationaltraining.utils.BitmapLoader;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.LogUtils;

/**
 * 主页新闻一项图片
 *
 * @author Administrator
 */
@EFragment(R.layout.item_fragment_home_news_image)
public class ItemHomeNewsImageFragment extends BaseFragment {
    @ViewById
    ImageView itemHomeNewImage;
    @FragmentArg
    int position;
    @FragmentArg
    String imageUrl;

    @AfterViews
    public void initView() {
        loadData();

    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
        loadData();
    }

    public void loadData() {
//        LogUtils.println(imageUrl);
        try {
            getBaseActivity().getDefaultBitmapLoader().displayImage(imageUrl, itemHomeNewImage, R.drawable.home_banner_1 + position);
        } catch (Exception e) {
            getBaseActivity().getDefaultBitmapLoader().displayImage(imageUrl, itemHomeNewImage, R.drawable.home_banner_1);
        }
    }

    public int getPosition() {
        return position;
    }

    @Click(R.id.itemHomeNewImage)
    public void itemHomeNewImageClick() {
//        if (position == 2) {
//
//            Intent intent = new Intent();
//            intent.setClassName(getActivity(),
//                    Constants.TRAINING_BULLETIN_ACTIVITY_CLASS_NAME);
//            intent.putExtra("cat", 4);
//            getActivity().startActivity(intent);
//        } else {
//
//            Intent intent = new Intent();
//            intent.setClassName(getActivity(),
//                    Constants.NEWS_LIST_ACTIVITY_CLASS_NAME);
//            if (position == 0) {
//                intent.putExtra("title", "他山之石");
//                intent.putExtra("cat", 1);
//            } else if (position == 1) {
//                intent.putExtra("title", "庖丁解车");
//                intent.putExtra("cat", 3);
//
//            } else if (position == 2) {
//                intent.putExtra("title", "三十六计");
//                intent.putExtra("cat", 2);
//            }
//            getActivity().startActivity(intent);
//        }
        try {
            HomeActivity homeActivity = (HomeActivity) getActivity();
            String title = "";
            String url = "";
            if (position == 0) {
                title = "三十六计";
                url = "http://borgwardapp.com/html/newslist1.php";
            } else if (position == 1) {
                title = "庖丁解车";
                url = "http://borgwardapp.com/html/newslist2.php";

            } else if (position == 2) {
                title = "培训公告";
                url = "http://borgwardapp.com/html/newslist3.php";
            } else {
                title = "不支持" + position;
                url = "http://borgwardapp.com/html/newslist1.php";
            }
            homeActivity.openHtml5Fragment(title, url);
        } catch (Exception ex) {
            ErrorUtils.outErrorLog(ex);
        }
    }
}
